package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 1 护理分页条件查询
     *
     * @return 分页结果
     */
    @GetMapping
    @ApiOperation(value = "护理分页条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理项目名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),

    })
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(Integer pageNum,
                                                                       Integer pageSize,
                                                                       String name,
                                                                       Integer status) {
        PageResponse<NursingProjectVo> pageInfo = nursingProjectService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);

    }


    /**
     * 2 新增
     */
    @PostMapping
    @ApiOperation(value = "新增")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }


    /**
     * 3 根据id查询护理
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理")
    public ResponseResult<NursingProjectVo> selectById(@PathVariable Long id) {

        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return success(nursingProjectVo);
    }

    /**
     * 4 编辑
     */
    @PutMapping
    @ApiOperation(value = "编辑")
    public ResponseResult edit(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.edit(nursingProjectDto);
        return success();
    }

    /**
     * 5 启用禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return success();
    }


    /**
     * 6 删除
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteProject(@PathVariable Long id) {
        nursingProjectService.deleteProject(id);
        return ResponseResult.success();
    }

    /**
     * 7 查询所有护理项目
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAllProject() {
        List<NursingProjectVo> nursingProjectVo = nursingProjectService.getAllProject();
        return success(nursingProjectVo);
    }


}
